package com.lmx.persistence.service;

import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.exception.BusinessException;
import com.lmx.repoDomain.tmodel.Appraise;

/**
 * 评价service实现
 *
 * @author ytche
 * @date 2017年7月21日
 *
 */
@Service(value = "appraiseService")
public class AppraiseServiceImpl extends BaseCrudServiceImpl<Appraise>
		implements AppraiseService {

	@Override
	public boolean checkPublish(Appraise entity) {
		Appraise oldData = super.findOne(entity.getId());
		if (oldData.getPublishStatus().equals(
				CommonConstants.DEFAULT_STATUS_YES_1)) {
			throw new BusinessException("",
					CommonConstants.APPRAISE_ERROE_CODE.PURLISHED.lable(),
					"该评价已经开始统计");
		}
		return entity.getPublishStatus().equals(
				CommonConstants.DEFAULT_STATUS_YES_1);
	}

	@Override
	public void publish(Appraise entity) {
		entity.setCompleteStatus(0);
		Appraise oldData = super.findOne(entity.getId());
		entity.setPublichNum(oldData.getPublichNum() + 1);
	}
}
